package com.jvm.socket.demo1;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 网络编程 nio 的学习
 * netty对nio封装
 * bio是阻塞的
 * QQServer和QQClient 就是以 bio 阻塞式模拟网络通信
 */
public class QQServer {

    static byte[] bytes = new byte[1024];

    public static void main(String[] args) {
        ServerSocket serverSocket = null;
        try {
            serverSocket = new ServerSocket();
            serverSocket.bind(new InetSocketAddress(8080));
            while (true){
                System.out.println("wait conn");
                // 会阻塞
                Socket socket = serverSocket.accept();

                System.out.println("conn success");
                System.out.println("wait data");
                // 会阻塞 read读取了多少字节
                int read = socket.getInputStream().read(bytes);
                System.out.println("data success");
                String content = new String(bytes);
                System.out.println("content: " + content);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
